from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base():
    def __init__(self):
        cap={

      "platformName": "Android",
      "appium:deviceName": "emulator-5554",
      "appium:automationName": "uiautomator2",
      "appium:appPackage": "com.xiachufang",
      "appium:appActivity": ".activity.home.HomeActivity",
      "appium:noReset": True
      }
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(20)

    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    def huadong(self,a,b,c,d):#滑动
        self.driver.swipe(a,b,c,d,300)
    def qingqiao(self,x,y):
        self.driver.tap([(x,y)],300)
    def jietu(self,a):
        self.driver.save_screenshot(a)
    def tuichu(self):
        self.driver.quit()
    def anjain(self,b):
        self.driver.press_keycode(b)
    def xianshi(self,loc):
        ele=WebDriverWait(self.driver,30).until(EC.element_to_be_clickable(loc))
    def long_press(self,loc):#长按
        ele=self.driver.find_element(loc)
        action=TouchAction(self.driver)
        action.long_press(el=ele,duration=2000).release().perform()

